﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InstantSpine.Core
{
    public sealed class NotifyingProperty<T> : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        T propertyData;
        
        public NotifyingProperty(T val = default(T)) {
            this.propertyData = val;
        }

        public T Value {
            get { return propertyData; }
            set {                
                if (!value.Equals(propertyData)) {
                    propertyData = value;
                    PropertyChanged.Raise(this);
                }
            }
        }

        public static implicit operator NotifyingProperty<T>(T val) {
            return new NotifyingProperty<T>(val);
        }

        public static implicit operator T(NotifyingProperty<T> notiVal) {
            return notiVal.Value;
        }
    }
}
